<?php
include("include/config.inc.php");
if(!isset($_SESSION['s_activId']))
{
  header("location:checklogin.php");
}

$truckArray = array();
if(isset($_POST['insertBtn']) && $_POST['truckNo'] !="")
{
	 $truckNo              = (isset($_POST['truckNo'])) && ($_POST['truckNo'] != "") ? $_POST['truckNo'] : "";
	 $regNo                = (isset($_POST['regNo'])) && ($_POST['regNo'] != "") ? $_POST['regNo'] : "";
	 $issueDate            = $_POST['issueYear']."-".$_POST['issueMonth']."-".$_POST['issueDay'];
	 $expDate              = $_POST['expDateYear']."-".$_POST['expDateMonth']."-".$_POST['expDateDay'];
	 $amount               = (isset($_POST['amount'])) && ($_POST['amount'] != "") ? $_POST['amount'] : 0 ;
	 $totalInstallment     = (isset($_POST['totalInstallment'])) && ($_POST['totalInstallment'] != "") ? $_POST['totalInstallment'] : 0 ;
	 $installmentAmount    = (isset($_POST['installmentAmount'])) && ($_POST['installmentAmount'] != "") ? $_POST['installmentAmount'] : 0 ;
	 $nationalPermit       = (isset($_POST['nationalPermit'])) && ($_POST['nationalPermit'] != "") ? $_POST['nationalPermit'] : "" ;
	 $nationalPermitAmount = (isset($_POST['nationalPermitAmount'])) && ($_POST['nationalPermitAmount'] != "") ? $_POST['nationalPermitAmount'] : 0 ;
	 $gujratTax            = (isset($_POST['gujratTax'])) && ($_POST['gujratTax'] != "") ? $_POST['gujratTax'] : 0 ;
	 $truckTo              = (isset($_POST['to'])) && ($_POST['to'] != "") ? $_POST['to'] : 0 ;
	 $passingDate          = $_POST['passingYear']."-".$_POST['passingMonth']."-".$_POST['passingDay'];
	 $pucDate              = $_POST['pucYear']."-".$_POST['pucMonth']."-".$_POST['pucDay'];
	 $installmentStartDate = $_POST['instalmentYear']."-".$_POST['instalmentMonth']."-".$_POST['instalmentDay'];

   $insertQuerytruck = "INSERT INTO truckmaster (truckNo,regNo,issueDate,expDate,amount,nationalPermit,nationalPermitAmount,gujratTax,
                                                     passingDate,pucDate,installmentStartDate,totalInstallment,installmentAmount)
                             VALUES(
                                    '".$truckNo."',
                            			  '".$regNo."',
                            			  '".$issueDate."',
                            			  '".$expDate."',
                            			  ".$amount.",
                            			  '".$nationalPermit."',
                            			  ".$nationalPermitAmount.",
                            			  ".$gujratTax.",
                            			  '".$passingDate."',
                            			  '".$pucDate."',
                            			  '".$installmentStartDate."',
                            			  ".$totalInstallment.",
                            			  ".$installmentAmount.")";
  $insertQuerytruckdResult = mysql_query($insertQuerytruck);
  if(!$insertQuerytruckdResult)
  {
    die("Insert Query Not Inserted : ".mysql_error());
  }
  else
    {
     header("Location:truck.php");
    }
}
$i = 0;
$selectTruck = "SELECT truckId,truckNo,regNo,DATE_FORMAT(issueDate,'%d-%m-%Y')AS issueDate,DATE_FORMAT(expDate,'%d-%m-%Y')AS expDate,
                       amount,nationalPermit,nationalPermitAmount,gujratTax,DATE_FORMAT(passingDate,'%d-%m-%Y')AS passingDate,
                       DATE_FORMAT(pucDate,'%d-%m-%Y')AS pucDate,
 											 DATE_FORMAT(installmentStartDate,'%d-%m-%Y')AS installmentStartDate,totalInstallment,installmentAmount
                      FROM truckmaster
                     ORDER BY truckId";
$selectTruckResult = mysql_query($selectTruck);
while($truckRow = mysql_fetch_array($selectTruckResult))
{
 $truckArray[$i]['truckId']                = $truckRow['truckId'];
 $truckArray[$i]['truckNo']                = $truckRow['truckNo'];
 $truckArray[$i]['regNo']                  = $truckRow['regNo'];
 $truckArray[$i]['issueDate']              = $truckRow['issueDate'];
 $truckArray[$i]['expDate']                = $truckRow['expDate'];
 $truckArray[$i]['amount']                 = $truckRow['amount'];
 $truckArray[$i]['nationalPermit']         = $truckRow['nationalPermit'];
 $truckArray[$i]['nationalPermitAmount']   = $truckRow['nationalPermitAmount'];
 $truckArray[$i]['gujratTax']              = $truckRow['gujratTax'];
 $truckArray[$i]['passingDate']            = $truckRow['passingDate'];
 $truckArray[$i]['pucDate']                = $truckRow['pucDate'];
 $truckArray[$i]['installmentStartDate']   = $truckRow['installmentStartDate'];
 $truckArray[$i]['totalInstallment']       = $truckRow['totalInstallment'];
 $truckArray[$i]['installmentAmount']      = $truckRow['installmentAmount'];
 $i++;
}


include("./bottom.php");
$smarty->assign('truckArray',$truckArray);
$smarty->display('truck.tpl');
?>